<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      {{obj.words}}
      <button @click="obj.words+='~'">++</button>
    </div>

    <script src="./vue.js"></script>
    <script>
      new Vue({
        el: "#app",
        data: {
          words: "苹果",
          obj: {
            words: "苹果",
            age: 19,
          },
        },
        methods: {},
        computed: {},
        watch: {
          // 1. 监听基本数据类型
          words(newV, oldV) {
            console.log("数据变化了  ----->  ", newV, oldV);
          },

          // 2. 监听复杂数据类型 (深度监听)
          obj: {
            handler(newV, oldV) {
              console.log("数据变化了  ----->  ", newV, oldV);
            },
            deep: true, // 开启深度监听
            immediate: true, // 立即执行
          },
        },
      });
    </script>
  </body>
</html>
